#include "data.h"

int main(int argc, char *argv[]){

	char buf[BUFSIZ] = {};
	struct config conf;
	struct data_transfer *dt = (struct data_transfer *)buf;
	int n;

	//1. 初始化客户端IP与port信息
	FT_InitConfig(&conf, false);

	//2. 准备套接字
	int fd = SocketInit(conf.ip, conf.port, false);

	//3. 根据客户端请求执行对应功能	
	while(1)
	{
		printf("********************************************\n");
		printf("1: insert  2:query  3:delete 4:update 5:quit\n");
		printf("********************************************\n");
		printf("Please select:");
		scanf("%d", &n);
		switch(n)
		{
		case 1:
			dt->type = TYPE_INSERT;
			printf("Input id:");
			scanf("%d", &dt->id);
			printf("Input name:");
			scanf("%s", dt->name);
			getchar();
			printf("Input sex:");
			scanf("%c", &dt->sex);
			printf("Input score:");
			scanf("%d", &dt->score);
			do_insert(fd, dt);
			break;
		case 2:
			dt->type = TYPE_QUERY;
			do_query(fd, dt);
			break;
		case 3:
			dt->type = TYPE_DELETE;
			printf("Input id:");
			scanf("%d", &dt->id);
			do_delete(fd, dt);
			break;
		case 4:
			dt->type = TYPE_UPDATE;
			printf("Input id:");
			scanf("%d", &dt->id);
			printf("Input name:");
			scanf("%s", dt->name);
			getchar();
			printf("Input sex:");
			scanf("%c", &dt->sex);
			printf("Input score:");
			scanf("%d", &dt->score);
			do_update(fd, dt);
			break;
		case 5:
			printf("main exit.\n");
			exit(0);
			break;
		default :
			printf("Invalid data n.\n"); 
		}
	}
}
